package searchtree;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        //Set里面不能存重复的数据，TreeSet底层是TreeMap
        Set<String> s=new TreeSet<>();
        s.add("hello");
        s.add("hello");
        s.add("abcd");
        System.out.println(s);

    }
    public static void main2(String[] args) {
        Map<String,Integer> map=new TreeMap<>();//key类型必须可比较
       // Map<String,Integer> map=new HashMap<>();//与上面的区别是没有排序，但是打印结果与存储数据不一致，key类型不用可比较
        // 原因：对于hasmap来说，他不是根据大小顺序存放的 底层：数组+链表+红黑树

        map.put("hello",3);
        map.put("hello",13);//会覆盖掉上一个

        map.put("abcd",2);
        map.put("bit",10);
//        System.out.println(map);//{abcd=2, bit=10, hello=3}
//        Integer ret=map.get("hello");
//        System.out.println(ret);//3
//        Integer ret1=map.getOrDefault("hello2",100);//没有hello2默认输出100
//        System.out.println(ret1);
//        Set<String> ret2=map.keySet();//返回key的不重复集合
//        System.out.println(ret2);
        Set<Map.Entry<String,Integer>> entrySet=map.entrySet();//返回所有的key-value映射关系，用得很多
        for (Map.Entry<String,Integer> entry:entrySet) {
            System.out.println("key: "+entry.getKey()+" val:"+entry.getValue());

        }

    }
    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree= new BinarySearchTree();
        int[] array={10,4,29,35,18,27,5,13};
        for (int i = 0; i < array.length; i++) {
            binarySearchTree.insert(array[i]);
        }
        boolean b=binarySearchTree.insert(35);
        binarySearchTree.inorder(binarySearchTree.root);
        System.out.println();
        System.out.println("查找：");
        BinarySearchTree.TreeNode ret=binarySearchTree.search(18);//1
        try{
            System.out.println(ret.key);
        }catch (NullPointerException e){
            System.out.println("没有你要查找的节点");
            e.printStackTrace();

        }
        binarySearchTree.remove(10);
        binarySearchTree.inorder(binarySearchTree.root);
        System.out.println();

    }
}
